{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Root locus diagrams\n", "\n", "Root locus diagrams show where the roots of the characteristic equation lie for different values of controller gain. The control library has a built-in function for plotting these diagrams." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import control" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from matplotlib import pyplot as plt" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "s = control.tf([1, 0], 1)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def rlocus(order, tau_p, K):\n", " Gp = 1/(tau_p*s + 1)**order\n", " Gc = 1\n", "\n", " L = Gp*Gc\n", " CL = K*L/(1 + K*L)\n", " control.root_locus(L);\n", " control.pzmap(CL)\n", " plt.title('')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from ipywidgets import interact" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7ef539c6f72d40299d04b6919c659bc1", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=3, description='order', max=5, min=1), FloatSlider(value=1.05, descripti…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "interact(rlocus, order=(1, 5), tau_p=(0.1, 2.), tau_i=(1., 20), K=(0.01, 200))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }